package com.app.bimo.module_bookrack.mvp.persenter;


import com.app.bimo.commonbusiness.mvp.BasePresenter;
import com.app.bimo.commonbusiness.network.RxObservableUtil;
import com.app.bimo.library_db.helper.SearchHotHelper;
import com.app.bimo.module_bookrack.mvp.constract.BookrackSearchContract;

public class BookrackSearchPresenter extends BasePresenter<BookrackSearchContract.Model, BookrackSearchContract.View> {
    public BookrackSearchPresenter(BookrackSearchContract.Model model, BookrackSearchContract.View rootView) {
        super(model, rootView);
    }

    /**
     * 搜索
     *
     * @param keyword
     * @param page
     */
    public void requestSearchFromModel(String keyword, int page) {
        RxObservableUtil.subscribe(
                mModel.getSearch(keyword, page)
                , bindCustomLifecycle(), bookStoreDataList -> {
                    // 处理数据 直接获取到List<JavaBean> carBeans
//                    if (page == 1 && bookStoreDataList.size() == 0) {
//                        mRootView.showSearchEmtyView();
//                    } else {
                        mRootView.searchNotify(bookStoreDataList);
//                    }
                });


    }

    /**
     * 热搜
     */
    public void requestHotSearchFromModel(boolean isRetry) {
        RxObservableUtil.subscribe(
                mModel.getHotSearch()
                , bindCustomLoadingLifecycle(true), bookStoreDataList -> {
                    // 处理数据 直接获取到List<JavaBean> carBeans
                    if (isRetry) {
                        mRootView.hideDialogLoading();
                    }
                    SearchHotHelper.getsInstance().saveHotSearch(bookStoreDataList);
                    mRootView.hotSearchNotify(bookStoreDataList);
                },e -> {
                    if (isRetry) {
                        mRootView.hideDialogLoading();
                    }
                });


    }


}
